<?php


namespace App\Http\Controllers\Api;


use App\Models\Content;
use App\Models\TradeProduct;
use App\Models\UserAsset;
use App\Services\Base\MsgService;
use Illuminate\Http\Request;

class ContentController extends ApiBaseController
{

    public function lists(Request $request, Content $content)
    {
        $data = $request->all();
        $data['lang'] = $this->getDefaultLang($request);
        $result = $content->getList($data);
        return $this->success($result);
    }

    public function home(Request $request, Content $content)
    {
        $assets = [
            "summary" => [
                "balance" => 0,
                "symbol" => "USD",
                "freeze" => 0,
            ],
            "USD" => [
                "balance" => 0,
                "freeze" => 0,
            ],
        ];
        $uid = $this->getUid($request);
        if ($uid) {
            $asset = UserAsset::getContractAccount($uid);
            $assets['summary']['balance'] = asMoney($asset->balance);
            $assets['summary']['freeze'] = asMoney($asset->freeze_balance + $asset->freeze_all);
            $assets['USD']['balance'] = asMoney($asset->balance);
            $assets['USD']['freeze'] = asMoney($asset->freeze_balance + $asset->freeze_all);
        }

        return $this->success([
            "languages" => MsgService::getLangList(),
            "slide" => [],
            "notification" => Content::notificationHome(),
            "quotations" => TradeProduct::homeList(),
            "assets" => $assets
        ]);
    }
}
